package edu.pku.hawk.datasource;

import edu.pku.hawk.controller.util.Config;
import edu.pku.hawk.controller.util.Constants;

public class DataGen {

	public static void main(String[] args) {

		Config.Singleton.Instance.initialize();
		
		int flag = 0;

		try {
			ConnectDB con =ConnectDB.getDBConnection(Constants.DataSource_Name,Constants.DataSource_Password, Constants.DataSource_URL, Constants.DataSource_DB);
			DataOperation insert = new DataOperation();
/*
			if (insert.CreatTable(con, "sensor_pressure", false))
				System.out.println("create table successfully.");
			else
				flag++;
			if (insert.CreatTable(con, "sensor_sound", false))
				System.out.println("create table successfully.");
			else
				flag++;
			if (insert.CreatTable(con, "sensor_smoke", false))
				System.out.println("create table successfully.");
			else
				flag++;
			if (insert.CreatTable(con, "sensor_infrared", true))
				System.out.println("create table successfully.");
			else
				flag++;
			if (insert.CreatTable(con, "sensor_metal", true))
				System.out.println("create table successfully.");
			else
				flag++;

			System.out.println("table create successfully.");
*/
			// --------------------------------------------------------------

			while (true) {
				try {
					Thread.sleep(Config.Singleton.Instance.MonitorLoopInterval);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
				
				flag = 0;
				if (insert.UpdateFloatValue1(con,  Constants.Pressure_Short_name))// "sensor_pressure"))

					;
				else
					flag++;
				if (insert.UpdateBooleanValue1(con,  Constants.Sound_Short_name))// "sensor_sound"))
					;
				else
					flag++;
				
				if (insert.UpdateBooleanValue1(con,  Constants.Infrared_Short_name)) //"sensor_infrared"))
					;
				else
					flag++;
				if (insert.UpdateBooleanValue1(con, Constants.Metal_Short_name)) // "sensor_metal"))
					;
				else
					flag++;
				if (insert.InsertRFIDValue1(con, Constants.RFID_Short_name)) // "sensor_metal"))
					;
				else
					flag++;

				if (flag == 0)
					;
				else
					System.out.println("Insert ERROR!");
				
//				con.commit();

			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

}
